package usaco.c2006.december.bronze;

import java.util.Scanner;

/*
 * p2838
 * USACO 2006 December - Bronze
 */

public class p2838 {

	static int C, B;
	static int[] feed;

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		C = scanner.nextInt();
		B = scanner.nextInt();
		feed = new int[B];
		for (int i=0;i<B;++i) {
			feed[i] = scanner.nextInt();
		}
		
		int upper = (1<<B) - 1;
		int max = 0;
		for (int i=0;i<=upper;++i) {
			int num = i;
			int sum = 0;
			for (int j=0;j<B;++j) {
				int re = num % 2;
				num /= 2;
				sum += re * feed[j];
				if (sum > C) {
					sum = max;
					break;
				}
			}
			if (sum > max) {
				max = sum;
			}
		}
		System.out.println(max);
	}

}
